#pragma once
#include "VC_Drawable.h"
#include "C_Fusion.h"

class C_SpaceShip;

class C_BitShip :
	public VC_Drawable
{
private:
	/////////////////////////////////////////////////////////////////////////////////
	//////	DRAWING PROPERTIES
	float m_dRoomSize;	// only room rectangle, without walls
	float m_dWallSize;  // pixels of wall size
	float *m_dRect;		// full size rectangle

	C_SpaceShip *m_spaceShip;

	S_Pointf m_pos;		// absolute position
	S_Pointi m_shipPos; // ship position

	/////////////////////////////////////////////////////////////////////////////////
	//////	TECHNICAL PROPERTIES
	C_Fusion* m_wallMaterial;	// wall material
	float	  m_wallSize;		// wall size
	C_Fusion* m_bindMaterial;	// bind material
	int		  m_bindAmt;		// bind amount
	C_Fusion* m_skinMaterial;	// skin material
	C_Fusion* m_wiringMaterial; // wiring material
	int		  m_area;			// area

	////////////////////////////////////////////////////////////////////
	//////	WALL SHOWED BOOLEAN VARIABLES
	bool	  m_leftWall;
	bool	  m_rightWall;
	bool	  m_topWall;
	bool	  m_bottomWall;

	///////////////////////////////////////////////////////////////////////
	//////////	PERCENT FOR COUNTING
	float m_pc;

	bool m_temporary;
	bool m_tempState;
	bool m_selected;
	bool m_over;

public:
	C_BitShip();
	virtual ~C_BitShip();

	void bind(C_SpaceShip* ss);

	/////////////////////////////////////////////////////////////////////////////////
	//////	SETTING FUNCTIONS
	inline void setWallMaterial(C_Fusion* f) { m_wallMaterial = f; }
	inline void setWallSize(float s) 
	{ 
		//testing
		m_wallSize = (s >= C_BitShip::m_constRectSide) ? C_BitShip::m_constRectSide : s;
		m_wallSize = (m_wallSize <= 0.0f) ? 0 : m_wallSize;
		m_wallSize = (m_wallSize >= 5.0f) ? 5 : m_wallSize;

		//counting area
		m_area = pow(C_BitShip::m_constRectSide - m_wallSize*2, 2); 
		//count drawing targets
		float relSize = (*m_dRect) / C_BitShip::m_constRectSide;
		m_dWallSize = m_wallSize * relSize;
		m_dRoomSize = (C_BitShip::m_constRectSide - (m_wallSize*2)) * relSize;
	}
	inline void setBindMaterial(C_Fusion* f) { m_bindMaterial = f; }
	inline void setBindAmt(int s) { m_bindAmt = (s <= 0) ? 0 : (s >= 100) ? 100 : s; }
	inline void setSkinMaterial(C_Fusion* f) { m_skinMaterial = f; }
	inline void setWiringMaterial(C_Fusion* f) { m_wiringMaterial = f; }

	/////////////////////////////////////////////////////////////////////////////////
	//////	MAIN FUNCTION
	virtual void handleEvent(sf::Event e);
	virtual void render();
	virtual void update();

	/////////////////////////////////////////////////////////////////////////////////
	//////	POSITION
	inline void		setPos(float x, float y) { m_pos.x = x; m_pos.y = y; }
	inline void		setShipPos(int x, int y) { m_shipPos.x = x; m_shipPos.y = y; }
	inline S_Pointi shipPos()				 { return m_shipPos; }

	void renderRect();

	/////////////////////////////////////////////////////////////////////////////////
	//////	CONST AREA
	static int m_constRectSide;

	void updateData()
	{
		float relSize = (*m_dRect) / C_BitShip::m_constRectSide;
		m_dWallSize = m_wallSize * relSize;
		m_dRoomSize = (C_BitShip::m_constRectSide - (m_wallSize * 2)) * relSize;
	}

	////////////////////////////////////////////////////////////////////
	//////	WALL SETTING
	void setWallShow(bool l, bool r, bool t, bool b) { m_leftWall = l; m_rightWall = r; m_topWall = t; m_bottomWall = b; }

	void hideLeftWall()		{ m_leftWall	= 0; }
	void hideRightWall()	{ m_rightWall	= 0; }
	void hideTopWall()		{ m_topWall		= 0; }
	void hideBottomWall()	{ m_bottomWall	= 0; }

	void showLeftWall()		{ m_leftWall	= 1; }
	void showRightWall()	{ m_rightWall	= 1; }
	void showTopWall()		{ m_topWall		= 1; }
	void showBottomWall()	{ m_bottomWall	= 1; }

	bool isLeftWall()	{ return m_leftWall;	}
	bool isRightWall()	{ return m_rightWall;	}
	bool isTopWall()	{ return m_topWall;		}
	bool isBottomWall() { return m_bottomWall;	}

	/////////////////////////////////////////////////////////////////////////////
	///////////	PERCENT
	void setPc(float pc) { m_pc = (pc > 100.0f) ? 100.0f : (pc < 0.0f) ? 0.0f : pc; }
	float pc() { return m_pc; }

	void setTemp(bool t)		{ m_temporary = t; }
	void setTempState(bool ts)	{ m_tempState = ts; }
	void setSelected(bool s)	{ m_selected = s; }
	void setOver(bool vr)		{ m_over = vr; }
	bool tempState()			{ return m_tempState; }

	/////////////////////////////////////////////////////////////////////////////////
	////////	GETTING
	float wallSize() { return m_wallSize; }
	int bindAmt() { return m_bindAmt; }
	int area() { return m_area; }
	C_Fusion* skin() { return m_skinMaterial; }
	C_Fusion* wiring() { return m_wiringMaterial; }

	friend class C_SpaceShip;
};

